package cn.com.ghy.android.bean;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.xmlpull.v1.XmlPullParser;

import android.util.Xml;

public class YeTaiTypeBeanParser {
	public static List<YeTaiTypeBean> parseXML(InputStream in) throws Exception {
		XmlPullParser parser = Xml.newPullParser();
		parser.setInput(in, "UTF-8");
		int type = parser.getEventType();

		YeTaiTypeBean bean = null;
		List<YeTaiTypeBean> list = null;

		while (type != XmlPullParser.END_DOCUMENT) {
			switch (type) {
				case XmlPullParser.START_DOCUMENT :
					list = new ArrayList<YeTaiTypeBean>();
					break;

				case XmlPullParser.START_TAG :
					if ("comb_yt".equals(parser.getName())) {
						bean = new YeTaiTypeBean();

					} else if (null != bean) {
						if ("YT".equals(parser.getName())) {
							bean.setYtCode(parser.nextText());
						} else if ("NAME1".equals(parser.getName())) {
							bean.setYtName(parser.nextText());
						}
					}
					break;

				case XmlPullParser.END_TAG :
					if ("comb_yt".equals(parser.getName())) {
						if (null != bean && null != list) {
							list.add(bean);
							bean = null;
						}
					}
					break;
			}
			type = parser.next();
		}
		in.close();
		return list;
	}
}
